<?php
/**
 * LogAction.class.php      系统日志操作类
 *
 * @author                  mashanling(msl-138@163.com)
 * @date                    2012-03-21 14:36:19
 * @last modify             2012-08-20 10:35:15 by mashanling
 */

!defined('ROOT') && exit('Access Denied');

class LogAction extends CommonAction {
    protected $priv_map = array(//权限映射
    	'delete' => '_list'//删除
    );
    /**
     * 管理员列表
     *
     * @return void 无返回值
     */
    function _list() {
        $sort      = Filter::string('sort', 'get', $this->pk_field);//排序字段
        $sort      = array_key_exists($sort, $this->getDbFields()) ? $sort : $this->pk_field;
        $order     = !empty($_GET['dir']) ? Filter::string('dir', 'get') : Filter::string('order', 'get');//排序
        $order     = toggle_order($order);
        $keyword   = Filter::string('keyword', 'get');//关键字
        $date_start= Filter::string('date_start', 'get');//注册开始时间
        $date_end  = Filter::string('date_end', 'get');//注册结束时间
        $log_type  = Filter::int('log_type', 'get');//日志类型
        $where     = $log_type != LOG_TYPE_ALL ? array( 'log_type' => $log_type) : array();

        if ($keyword !== '') {
            $where['content'] = $this->buildMatchQuery('content', $keyword, Filter::string('match_mode', 'get'));
        }

        if ($date_start && ($date_start = local_strtotime($date_start))) {
            $where['log_time'][] = array('EGT', $date_start);
        }

        if ($date_end && ($date_end = local_strtotime($date_end))) {
            $where['log_time'][] = array('ELT', $date_end);
        }

        if (isset($where['log_time']) && count($where['log_time']) == 1) {
            $where['log_time'] = $where['log_time'][0];
        }

        $total      = $this->model->where($where)->count();

        if ($total === false) {//查询出错
            $this->sqlErrorExit(L('QUERY,MODULE_NAME_LOG') . L('TOTAL_NUM,ERROR'));
        }
        elseif ($total == 0) {//无记录
            $this->ajaxReturn(array('total' => $total));
        }

        $page_info = Filter::page($total);
        $data      = $this->model->where($where)->field('*,INET_NTOA(admin_ip) AS admin_ip')->limit($page_info['limit'])->order('' .$sort . ' ' . $order)->select();

        $data === false && $this->sqlErrorExit(L('QUERY,MODULE_NAME_LOG') . L('LIST,ERROR'));//出错

        $data      = array('total' => $total, 'root' => $data, 'sql' => $this->model->getLastSql());
        $this->ajaxReturn($data);
    }//end index

    /**
     *
     * @see CommonAction::beforeExec()
     */
    protected function beforeExec(&$pk_id, &$log) {
        $log = join(', ', $pk_id);//操作日志

        return null;
    }
}